package com.tianji.learning.service.impl;

import com.tianji.common.utils.BeanUtils;
import com.tianji.learning.domain.po.PointsBoardSeason;
import com.tianji.learning.domain.vo.PointsBoardSeasonVO;
import com.tianji.learning.mapper.PointsBoardSeasonMapper;
import com.tianji.learning.service.IPointsBoardSeasonService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

import static com.tianji.learning.constans.LearningConstants.POINTS_BOARD_TABLE_PREFIX;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author mxl
 * @since 2024-06-28
 */
@Service
public class PointsBoardSeasonServiceImpl extends ServiceImpl<PointsBoardSeasonMapper, PointsBoardSeason> implements IPointsBoardSeasonService {

    @Override
    public List<PointsBoardSeasonVO> getList() {
        // 1. 查寻全部赛季信息
        List<PointsBoardSeason> records = this.list();
        //2.封装vo
        List<PointsBoardSeasonVO> voList = records.stream()
                .map((record) -> BeanUtils.copyBean(record, PointsBoardSeasonVO.class))
                .collect(Collectors.toList());
        return voList;
    }

    @Override
    public void createPointBoardLatestSession(Integer id) {
        getBaseMapper().createPointBoardTable(POINTS_BOARD_TABLE_PREFIX+id);
    }
}
